const app = getApp()

Page({
  data:{
    showIcon:true,
    swiperList:[],
    item:[],
    seachList:null
  },
  onLoad()
  { 
    wx.cloud.callFunction({
      name:'banner'
    })
    .then(res=>{
      console.log(res.result.data)
      this.setData({
        swiperList:res.result.data
      })
    })
    .catch(err=>{
      console.error(err)
    })

    wx.cloud.callFunction({
      name:'shop'
    })
    .then(res=>{
      console.log(res.result.data)
      this.data.item = res.result.data
      this.setData({
        list:res.result.data
      })
    })
    .catch(err=>{
      console.error(err)
    })
  },
  handleInputChange(e)
  {
    const value = e.detail.value;
    let searchList = null;
    if(value)
    {
      searchList = this.data.item.filter(item => 
        item.name.indexOf(value) > -1);
    }
    this.setData({
      showIcon: value ? false : true,
      searchList
    })
  },
  changeType(e) {
    const type = e.currentTarget.dataset.type;
    // console.log(type);
    this.setData({ type });
  },
  jumpItem(e)
  {
    //  console.log(e);
    const {id} = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/shop/shop?id=${id}`,
    })
  }
})